#!/usr/bin/env python
# encoding: utf-8

import os

def configure(cfg):
    print('libs/startup configure')
    
def build(bld):
    print('libs/startup/startup build')
    
    objs = []
    src_count = 1
    
    startup_src = []
    
    
    def endWith(s,*endstring):
        array = map(s.endswith,endstring)
        if True in array:
            return True
        else:
            return False
    
    file_list = os.listdir(bld.path.abspath())
    for file in file_list:
        if endWith(file,'.S','.s','.c','.cpp'):
            startup_src.append(file)
        
    for src in startup_src:
        obj = src + '.' + str(src_count) + '.o'
        objs.append(obj)
        dep = src + '.' + str(src_count) + '.d'
        lst = src + '.' + str(src_count) + '.lst'
        src_count += 1

        bld.objects(source=src, 
                    target=obj,
                    defines='DEFTESTY=1 DEFTESTN=0',
                    includes='../inctest',
                    asflags='-MD -MP -MFdeps/%s -Wa,-amhls=lsts/%s' %(dep,lst),
                    cflags='-MD -MP -MFdeps/%s -Wa,-amhls=lsts/%s' %(dep,lst),
                    cxxflags='-MD -MP -MFdeps/%s -Wa,-amhls=lsts/%s' %(dep,lst))
    
    bld.stlib(source='',
              target='startup',
              use=objs,
              features="cxx cxxstlib")
    